/*    */ package com.equipmentmanage.dao.impl;
/*    */ 
/*    */ import com.equipmentmanage.dao.DepartmentDao;
import com.equipmentmanage.model.Department;
import com.equipmentmanage.model.PageBean;
import com.equipmentmanage.util.StringUtil;

/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import javax.annotation.Resource;
/*    */ import org.springframework.jdbc.core.JdbcTemplate;
/*    */ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
/*    */ 
/*    */ @Repository("departmentDao")
/*    */ public class DepartmentDaoImpl
/*    */   implements DepartmentDao
/*    */ {
/*    */ 
/*    */   @Resource
/*    */   private JdbcTemplate jdbcTemplate;
/*    */ 
/*    */   public void add(Department department)
/*    */   {
/* 31 */     String sql = "insert into t_department values(null,?,?)";
/* 32 */     this.jdbcTemplate.update(sql, new Object[] { department.getDeptName(), department.getRemark() });
/*    */   }
/*    */ 
/*    */   public void update(Department department)
/*    */   {
/* 37 */     String sql = "update t_department set deptName=?,remark=? where id=?";
/* 38 */     this.jdbcTemplate.update(sql, new Object[] { department.getDeptName(), department.getRemark(), department.getId() });
/*    */   }
/*    */ 
/*    */   public void delete(int id)
/*    */   {
/* 43 */     String sql = "delete from t_department where id=?";
/* 44 */     this.jdbcTemplate.update(sql, new Object[] { Integer.valueOf(id) });
/*    */   }
/*    */ 
/*    */   public List<Department> find(PageBean pageBean, Department s_department)
/*    */   {
/* 49 */     StringBuffer sb = new StringBuffer("select * from t_department");
/* 50 */     if ((s_department != null) && 
/* 51 */       (StringUtil.isNotEmpty(s_department.getDeptName()))) {
/* 52 */       sb.append(" and deptName like '%" + s_department.getDeptName() + "%'");
/*    */     }
/*    */ 
/* 55 */     if (pageBean != null) {
/* 56 */       sb.append(" limit " + pageBean.getStart() + "," + pageBean.getPageSize());
/*    */     }
/* 58 */     final List departmentList = new ArrayList();
/* 59 */     this.jdbcTemplate.query(sb.toString().replaceFirst("and", "where"), new Object[0], new RowCallbackHandler()
/*    */     {
/*    */       public void processRow(ResultSet rs) throws SQLException
/*    */       {
/* 63 */         Department department = new Department();
/* 64 */         department.setId(Integer.valueOf(rs.getInt("id")));
/* 65 */         department.setDeptName(rs.getString("deptName"));
/* 66 */         department.setRemark(rs.getString("remark"));
/* 67 */         departmentList.add(department);
/*    */       }
/*    */     });
/* 70 */     return departmentList;
/*    */   }
/*    */ 
/*    */   public int count(Department s_department) {
/* 74 */     StringBuffer sb = new StringBuffer("select count(*) from t_department");
/* 75 */     if ((s_department != null) && 
/* 76 */       (StringUtil.isNotEmpty(s_department.getDeptName()))) {
/* 77 */       sb.append(" and deptName like '%" + s_department.getDeptName() + "%'");
/*    */     }
/*    */ 
/* 80 */     return ((Integer)this.jdbcTemplate.queryForObject(sb.toString().replaceFirst("and", "where"), Integer.class)).intValue();
/*    */   }
/*    */ 
/*    */   public Department loadById(int id) {
/* 84 */     String sql = "select * from t_department where id=? ";
/* 85 */     final Department department = new Department();
/* 86 */     this.jdbcTemplate.query(sql, new Object[] { Integer.valueOf(id) }, new RowCallbackHandler()
/*    */     {
/*    */       public void processRow(ResultSet rs) throws SQLException
/*    */       {
/* 90 */         department.setId(Integer.valueOf(rs.getInt("id")));
/* 91 */         department.setDeptName(rs.getString("deptName"));
/* 92 */         department.setRemark(rs.getString("remark"));
/*    */       }
/*    */     });
/* 95 */     return department;
/*    */   }
/*    */ }

/* Location:           C:\Users\arcgis\Desktop\新建文件夹\a0\[www.java1234.com]《SpringMvc设备管理系统》第零讲源码及文档\EquipmentSys\WEB-INF\classes\
 * Qualified Name:     com.java1234.dao.impl.DepartmentDaoImpl
 * JD-Core Version:    0.6.1
 */